<?php $this->load->view('header');?>

<body class="childrenBody custom_body">
	<div class="custom_main">
		<fieldset class="layui-elem-field layui-field-title">
		  <legend>基础信息</legend>
		</fieldset>

		<form class="layui-form">
			<div class="layui-form-item">
				<label class="layui-form-label">头像：</label>
				<div class="layui-upload">
				  <button type="button" class="layui-btn layui-btn-primary" id="test1">上传</button>
				  <div class="layui-upload-list" style="display: inline;">
				    <img class="layui-upload-img" id="demo1">
				    <p id="demoText" style="display: inline;color: #ccc">建议正方形图片，大小不超过2M。支持格式jpg、jpeg、gif、png</p>
				  </div>
				  <input type="hidden" name="headimg" value="<?=$headimg?>" />
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label custom_i"><i>*</i> 姓名：</label>
				<div class="layui-input-inline">
					<input type="text" name="nickname" required lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input" value="<?=$nickname?>">
				</div> 
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label custom_i"><i>*</i> 性别：</label>
				<div class="layui-input-block">
					<input type="radio" name="sex" value="1" title="男"  checked >
      				<input type="radio" name="sex" value="2" title="女" <?php if ($sex == 2):?> checked <?php endif;?>>
				</div>
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label custom_i"><i>*</i> 手机：</label>
				<div class="layui-input-inline">
					<input type="text" name="mobile" required lay-verify="required" placeholder="请输入手机" autocomplete="off" class="layui-input" value="<?=$mobile?>">
				</div> 
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label custom_i"><i>*</i> 所属场馆：</label>
				<div class="layui-input-block" id="check_l">
					<?php foreach ($venue as $item):?>
					<!--<input type="checkbox" name="shop_id" title="<?=$item['name']?>" lay-skin="primary" lay-verify="checkboxmustbe" id="venue" value="<?=$item['id']?>" <?php if ($item['id'] == $shop_id):?> checked <?php endif;?>/> -->
					<input type="radio" name="shop_id" value="<?=$item['id']?>" <?php if(!$shop_id):?> lay-verify="checkboxmustbe" <?php endif;?> class="venue" title="<?=$item['name']?>"  <?php if ($item['id'] == $shop_id):?> checked <?php endif;?> >
					<?php endforeach;?>
				</div> 
			</div>

			<div class="layui-form-item">
				<label class="layui-form-label custom_i"><i>*</i> 排序权重：</label>
				<div class="layui-input-inline">
					<input type="text" name="is_sort" required lay-verify="required" placeholder="只可输入数字" autocomplete="off" class="layui-input" value="<?=$is_sort?>">
				</div> 
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">简介：</label>
			    <div class="layui-input-block">
			      <textarea name="info" placeholder="请输入简介" class="layui-textarea"><?=$info?></textarea>
			    </div>
			</div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<input type="hidden" name="coach_id" value="<?=$id?>" />
					<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="addUser">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			    </div>
			</div>
		</form>
		
	</div>

	<script type="text/javascript">
		layui.config({
			version: true
		}).use(['jquery','layer', 'form', 'laytpl', 'upload'],function(){
			var form = layui.form,
				layer = parent.layer === undefined ? layui.layer : parent.layer,
				laypage = layui.laypage,
				laytpl = layui.laytpl,
				upload = layui.upload,
				$ = layui.jquery;

				//自定义验证规则  
				/*form.verify({
					checkboxmustbe: function(){						
						if (!$("#venue").is(":checked")) {
							return "必须选择场馆";
						}
			        }
				});/*/
			

			var image_load = '<?=$image_upload_url?>';

			//上传图片
			var uploadInst = upload.render({
			    elem: '#test1'
			    ,url: image_load
			    ,before: function(obj){
			      //预读本地文件示例，不支持ie8
			      obj.preview(function(index, file, result){
			        $('#demo1').attr('src', result); //图片链接（base64）
			        $("#demo1").css("width","100px");
			      });
			    }
			    ,done: function(res){
			      //如果上传失败
			      if(res.result_code > 0){
			        return layer.msg('上传失败');
			      } 
			      //上传成功
			      else{
			      	$("input[name='headimg']").val(res.data[0].url);
			      }
			     
			    }
			    ,error: function(){
			      //演示失败状态，并实现重传
			      var demoText = $('#demoText');
			      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
			      demoText.find('.demo-reload').on('click', function(){
			        uploadInst.upload();
			      });
			    }
			  });

				//提交表单
				form.on("submit(addUser)",function(data)
				{

					$.post('admin.php/Coach/insert_add', data.field, function(result) {
						if (result.status == 200) 
						{
							layer.msg(result.message, {icon: 1});
							location.reload();
						}
						else
						{
							layer.msg(result.message, {icon: 5});
						}

					},"json");

					return false;
				});

				form.render(); //更新全部

		});

	</script>

</body>
</html>